<%@ page language="java" pageEncoding="UTF-8"
	errorPage="../../defaultException.jsp"%>
<%@include file="../../tags.jsp"%>
<html>
<head>
<title>酒店资源子项信息管理</title>
<%@include file="../../head.jsp"%>


</head>
<body>
	<table id="list_data" cellspacing="0" cellpadding="0">
		<thead>
			<tr>
				<th field="imageId">特色项图片编号</th>
				<th field="source" formatter="formatCell">特色项图片</th>
			</tr>
		</thead>
	</table>

	<div id="addHotelResourceInfoDialog"
		style="width: 400px; height: 280px; padding: 10px 20px"></div>

	<script type="text/javascript">
		function formatCell(value, row, index) {
			return "<img src='${image_domain}"+value+"@!small' width='150' height='100'>";
		}
		function renderPick(value, row, index) {
			return "<input type='radio' name='pick' data-index='"+index+"'/>";
		}
		$('#list_data')
				.datagrid(
						{
							title : '<a href=${cpath }/admin/dest/vlist>目的地</a>&gt&gt'
								+ '<a href=${cpath }/admin/hotel/vlist?destId=${dest.destId}>'
								+ '<c:out value="${dest.zhname}" escapeXml="true"/>酒店</a>&gt&gt<a href=${cpath }/admin/hotel/text/vlist?hotelId=${hotel.hotelId}>'
									+ '<c:out value="${hotel.zhname}" escapeXml="true"/></a>'
									+ '&gt&gt<c:out value="${info.zhname}" escapeXml="true" />',
							iconCls : 'icon-edit',//图标 
							width : 1024,
							height : 'auto',
							nowrap : false,
							striped : true,
							border : true,
							collapsible : false,//是否可折叠的 
							fitColumns : true,//自动大小 
							fit : true,
							url : '${cpath }/admin/hotel/image/list?infoId=${info.infoId}',
							remoteSort : false,
							idField : 'imageId',
							singleSelect : true,//是否单选 
							pagination : false,//分页控件 
							rownumbers : true,//行号 
							toolbar : [
									{
										text : '添加图片',
										iconCls : 'icon-add',
										handler : function() {
											var saveAction = cpath
													+ '/admin/hotel/image/save?infoId=${info.infoId}';
											var openAction = cpath
													+ '/admin/hotel/image/vsave';
											openAddHotelImageDialog(
													'添加图片', openAction,
													saveAction,
													addHotelImageSuccess);
										}
									},
									'-',
									{
										text : '修改图片',
										iconCls : 'icon-edit',
										handler : function() {
											var saveAction = cpath
													+ '/admin/hotel/image/update';
											var openAction = cpath
													+ '/admin/hotel/image/vupdate';
											openAddHotelImageDialog('修改图片',
													openAction, saveAction,
													addHotelImageSuccess,
													getSelectHotelImage);
										}
									},
									'-',
									{
										text : '删除资源子项',
										iconCls : 'icon-remove',
										handler : function() {
											//openDialog("add_dialog","add");
											var deleteAction = cpath
													+ '/admin/hotel/image/delete';
											deleteResourceItem(deleteAction,
													getSelectHotelImage);
										}
									}, '-', {
										text : '刷新',
										iconCls : 'icon-reload',
										handler : function() {
											$('#list_data').datagrid('reload');
											save_status = false;
										}
									} ]
						});
	</script>
	<script type="text/javascript">
		var url;
		var cpath = '${cpath}';
		function addHotelImageSuccess() {
			$('#list_data').datagrid('reload'); // reload the user data
		}
		function getSelectHotelImage() {
			return $('#list_data').datagrid('getSelected');
		}
		function openAddHotelImageDialog(dlgtitle, openAction, saveAction,
				successCallback, getSelectHotel) {
			//添加信息，需要是否有前置条件
			if (getSelectHotel) {
				var row = getSelectHotel();
				//没有选中行，则需要提示
				if (!row) {
					$.messager.alert("提示", "请选择一条图片信息！", "info");
					return;
				} else {
					//选中了一行需在saveAction后加上目的地编号
					openAction += '?imageId=' + row.imageId;
				}
			}
			$('#addHotelResourceInfoDialog').dialog({
				title : dlgtitle,
				width : 600,
				height : 300,
				closed : false,
				cache : false,
				resizable : true,
				href : openAction,
				modal : true,
				closed : true,
				buttons : [ {
					text : '保存',
					iconCls : "icon-ok",
					handler : function() {
						saveHotelBaseInfoForm(saveAction, successCallback);
					}
				}, {
					text : '取消',
					iconCls : "icon-cancel",
					handler : function() {
						$('#addHotelResourceInfoDialog').dialog('close');
					}
				} ]
			});
			$('#addHotelResourceInfoDialog').dialog('open');
		}
		var save_status = false;
		function saveHotelBaseInfoForm(saveAction, successCallback) {
			if (save_status) {
				$.messager.alert("提示", "请耐心等待。。。后台执行中。。。", "info");
				return;
			}
			save_status = true;
			$('#fm').form('submit', {
				url : saveAction,
				onSubmit : function() {
					var result = $(this).form('validate');
					if (!result) {
						save_status = false;
					}
					return result;
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.resultCode !== '00000000') {
						$.messager.alert("错误", result.resultMsg, "error");
						$('#list_data').datagrid('clearSelections');
					} else {
						$.messager.alert("成功", result.resultMsg, "info");
						$('#addHotelResourceInfoDialog').dialog('close');
						if (successCallback) {
							successCallback();
						}
						$('#list_data').datagrid('clearSelections');
					}
					save_status = false;
				}
			});
		}

		var checkedImageId = '${item.imageId}';

		function deleteResourceItem(deleteAction, getSelectResourceItem) {
			//添加信息，需要是否有前置条件
			if (getSelectResourceItem) {

				var row = getSelectResourceItem();
				//没有选中行，则需要提示
				if (!row) {
					$.messager.alert("提示", "请选择要删除的资源子项！", "info");
					return;
				}
				if (row) {
					//默认图片不可以删除
					if (row.imageId == checkedImageId) {
						$.messager.alert("提示", "默认图片不可以删除！", "info");
						return;
					}
					$.messager.confirm("提示", "确认要删除资源子项吗？", function(r) {
						if (r) {
							$.post(deleteAction, row,
									function(result) {
										if (result.resultCode === '00000000') {
											$('#list_data').datagrid('reload'); // reload the user data
											$.messager.alert("提示",
													result.resultMsg, "info");
											$('#list_data').datagrid(
													'clearSelections');
										} else {
											$.messager.alert("错误",
													result.resultMsg, "error");
											$('#list_data').datagrid(
													'clearSelections');
										}
									}, 'json');
						}
					});
				}
			}
		}
	</script>
</body>
</html>